<html>
<head><meta charset="utf-8"><title>rainbow mode · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html">rainbow mode</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="171251059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171251059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171251059">(Jul 19 2019 at 12:01)</a>:</h4>
<p>Is it me, or is the rainbow mode a little unreliable?</p>
<p><a href="/user_uploads/4715/1QYCfLct27ihzsix-BxGu99T/pasted_image.png" target="_blank" title="pasted_image.png">pasted image</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/1QYCfLct27ihzsix-BxGu99T/pasted_image.png" target="_blank" title="pasted image"><img src="/user_uploads/4715/1QYCfLct27ihzsix-BxGu99T/pasted_image.png"></a></div>



<a name="171251088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171251088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171251088">(Jul 19 2019 at 12:01)</a>:</h4>
<p>also, it doesn't seem to handle toggling the preference</p>



<a name="171251095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171251095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171251095">(Jul 19 2019 at 12:01)</a>:</h4>
<p><a href="/user_uploads/4715/6mNNXRW_n5L6uqCiyxs_sSwE/pasted_image.png" target="_blank" title="pasted_image.png">pasted image</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/6mNNXRW_n5L6uqCiyxs_sSwE/pasted_image.png" target="_blank" title="pasted image"><img src="/user_uploads/4715/6mNNXRW_n5L6uqCiyxs_sSwE/pasted_image.png"></a></div>



<a name="171251158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171251158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171251158">(Jul 19 2019 at 12:02)</a>:</h4>
<p>here I disabled it so the underlines from <a href="https://github.com/rust-lang/rust/issues/1550" target="_blank" title="https://github.com/rust-lang/rust/issues/1550">#1550</a> show, but the colors don't change unless I re-open the editor window</p>



<a name="171251515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171251515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171251515">(Jul 19 2019 at 12:08)</a>:</h4>
<p>Hm, yeah, it seems like rainbow mode is not properly cleared on modification...</p>



<a name="171251548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171251548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171251548">(Jul 19 2019 at 12:09)</a>:</h4>
<p><a href="/user_uploads/4715/u9mQkuenQPkQ3jcsgccwyx-F/pasted_image.png" target="_blank" title="pasted_image.png">pasted image</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/u9mQkuenQPkQ3jcsgccwyx-F/pasted_image.png" target="_blank" title="pasted image"><img src="/user_uploads/4715/u9mQkuenQPkQ3jcsgccwyx-F/pasted_image.png"></a></div>



<a name="171251557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171251557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171251557">(Jul 19 2019 at 12:09)</a>:</h4>
<p>ugh, not sure if I broke it or it's wrong</p>



<a name="171252062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252062">(Jul 19 2019 at 12:16)</a>:</h4>
<p>So I see at least two problems</p>



<a name="171252084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252084">(Jul 19 2019 at 12:17)</a>:</h4>
<ul>
<li>decorations are never cleared. This seems preexisting</li>
<li>it looks like we add <code>mut</code> when we compute hash? This could be introduced recently, and should be fixed in the hir level (working on it<br>
)</li>
</ul>



<a name="171252146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252146">(Jul 19 2019 at 12:18)</a>:</h4>
<p>yeah, that seems likely</p>



<a name="171252155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252155">(Jul 19 2019 at 12:18)</a>:</h4>
<p>I can send you a patch for underlining in rainbow mode</p>



<a name="171252188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252188">(Jul 19 2019 at 12:19)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="117482">@Pascal</span> I am looking at this code, and this seems wrong to me (IIRC, you are the author):</p>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/f209843e31af7f0e0212aa28ffec2efad2a70c6f/editors/code/src/highlighting.ts#L134-L137" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/f209843e31af7f0e0212aa28ffec2efad2a70c6f/editors/code/src/highlighting.ts#L134-L137">https://github.com/rust-analyzer/rust-analyzer/blob/f209843e31af7f0e0212aa28ffec2efad2a70c6f/editors/code/src/highlighting.ts#L134-L137</a></p>
<p>We create a fresh decoration on every re-highlighting, but we never clear highlighting ranges</p>



<a name="171252210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252210">(Jul 19 2019 at 12:20)</a>:</h4>
<p>I think we should do one of the following:</p>
<ul>
<li>precompute some fixed set of colors</li>
<li>on every loop, remember the set of decorations we've applied, and explicitelly clear it</li>
</ul>



<a name="171252263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252263">(Jul 19 2019 at 12:20)</a>:</h4>
<p>(<span aria-label="confused" class="emoji emoji-1f615" role="img" title="confused">:confused:</span> why doesn't JS's <code>Map</code> have a way to avoid double lookups as in<code>has</code>, then <code>set</code>?)</p>



<a name="171252307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pascal <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252307">(Jul 19 2019 at 12:21)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> oh, the highlights don't overwrite each other? :O i think that was my assumption when writing that</p>



<a name="171252394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252394">(Jul 19 2019 at 12:22)</a>:</h4>
<p>apparently they're removed when the config changes, but only if the highlighting is disabled</p>



<a name="171252411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252411">(Jul 19 2019 at 12:22)</a>:</h4>
<p>which is why toggling rainbow mode doesn't clear them</p>



<a name="171252429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pascal <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252429">(Jul 19 2019 at 12:23)</a>:</h4>
<p>hm. how do you clear decorations? if we can put these <code>dec</code>s in a map and go through them before applying this might be super slow</p>



<a name="171252529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pascal <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252529">(Jul 19 2019 at 12:24)</a>:</h4>
<p>if we make the <code>fancify</code> function use less entropy we can probably get down to a few dozen colors, but i'm not an expert on this at all</p>



<a name="171252578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252578">(Jul 19 2019 at 12:25)</a>:</h4>
<blockquote>
<p>hm. how do you clear decorations? </p>
</blockquote>
<p><code>editor.setDecorations(dec, [])</code>. Perhaps there's an explicit method to dispose the decoration as well</p>



<a name="171252660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252660">(Jul 19 2019 at 12:27)</a>:</h4>
<blockquote>
<p>I can send you a patch for underlining in rainbow mode</p>
</blockquote>
<p>ah, you've already implemented that (small nit: you can move <code>textDecoration</code> outside of the <code>light</code>/<code>dark</code> options)</p>



<a name="171252776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pascal <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252776">(Jul 19 2019 at 12:28)</a>:</h4>
<p>ok, how about this: adjust fancify so it uses a smaller range for h, s, and l (and expand with <code>*3</code> at the end or something) and make the l component be flipped instead of two uniq random values. then build a Map&lt;HSL, Decoration&gt; and hope it's only ~300 entries?</p>



<a name="171252896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pascal <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252896">(Jul 19 2019 at 12:30)</a>:</h4>
<p>the advantage of using the random seeding is that it's stable across files so identifiers have the same color in two panels</p>



<a name="171252902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171252902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171252902">(Jul 19 2019 at 12:30)</a>:</h4>
<blockquote>
<p><code>editor.setDecorations(dec, [])</code>. Perhaps there's an explicit method to dispose the decoration as well</p>
</blockquote>
<p>there is</p>



<a name="171253057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171253057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171253057">(Jul 19 2019 at 12:32)</a>:</h4>
<p><span class="user-mention" data-user-id="117482">@Pascal</span> sgtm!</p>



<a name="171253171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171253171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pascal <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171253171">(Jul 19 2019 at 12:34)</a>:</h4>
<p>i won't have time to work on this for the next week or so but just ping me if you want me to look at stuff :)</p>



<a name="171253324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171253324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171253324">(Jul 19 2019 at 12:37)</a>:</h4>
<p>sure, thanks!</p>



<a name="171253517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171253517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171253517">(Jul 19 2019 at 12:40)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> how do you feel about enabling trailing commas in the prettier config?</p>



<a name="171253553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rainbow%20mode/near/171253553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rainbow.20mode.html#171253553">(Jul 19 2019 at 12:41)</a>:</h4>
<p>I am mildly in favor, but, mainly, I have no idea about typescript current best-pracices, so I am happy to just defer to anybody more knoledgable :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>